<template>
	<view class="cart-container" v-if="cart.length !== 0">
		<!-- 收货地址 -->
		<my-address>
		</my-address>
		<view class="cart-title">
			<!-- 购物车商品列表的标题区域 -->
			<!-- 左侧图标 -->
			<uni-icons type="shop" size="18"></uni-icons>
			<!-- 描述文本 -->
			<text class="cart-title-text">购物车</text>
		</view>
		<!-- 商品列表区域 -->
		<uni-swipe-action>
			<block v-for="(goods, i) in cart" :key = "i">
				<uni-swipe-action-item :options="options" @click="">
					<my-goods @radio-change="radioChangeHandler" :showNum="true" :goods="goods" :showRadio = "true" @num-change="numberChangeHandler"></my-goods>	
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		
		<!-- 底部结算区域 -->
		<my-settle></my-settle>
	</view>
	<view class="empty-container" v-else>
		<text>空空如也~</text>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	import mixBadge from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [mixBadge],
		data() {
			return {	
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#C00000'
					} 
				}]
			}
		},

		computed: {
			// 将m_cart 模块中的total 映射为当前页面的计算属性
			...mapState('m_cart', ['cart']),
		},
		methods: {
			...mapMutations('m_cart',['updateGoodsState', 'updateGoodsCount']),
			radioChangeHandler(e) {
				this.updateGoodsState(e)
			},
			numberChangeHandler(e) {
				this.updateGoodsCount(e)
			}
		}
	}
</script>

<style lang="scss">
	.cart-container {
		padding-bottom: 50px;
	}
	.cart-title {
		padding-left: 5px;
		height: 40px;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #F0F0F0;
		.cart-title-text {
			margin-left: 10px;
		}
	}
	.empty-containe {
		display: flex;
		align-items: center;
		align-items: center;
	}
</style>
